from tortoise import fields
from datetime import datetime
from .base import BaseModel, TimestampMixin


class SysMenu(BaseModel, TimestampMixin):
    """菜单权限表"""

    menu_id = fields.IntField(pk=True, description="菜单ID")

    menu_name = fields.CharField(max_length=50, description="菜单名称")

    parent_id = fields.IntField(null=True, description="父菜单ID")

    order_num = fields.IntField(null=True, description="显示顺序")

    path = fields.CharField(max_length=200, null=True, description="路由地址")

    component = fields.CharField(max_length=255, null=True, description="组件路径")

    query = fields.CharField(max_length=255, null=True, description="路由参数")

    route_name = fields.CharField(max_length=50, null=True, description="路由名称")

    is_frame = fields.IntField(null=True, description="是否为外链（0是 1否）")

    is_cache = fields.IntField(null=True, description="是否缓存（0缓存 1不缓存）")

    menu_type = fields.CharField(max_length=1, null=True, description="菜单类型（M目录 C菜单 F按钮）")

    visible = fields.CharField(max_length=1, null=True, description="菜单状态（0显示 1隐藏）")

    status = fields.CharField(max_length=1, null=True, description="菜单状态（0正常 2删除）")

    use_flag = fields.CharField(max_length=1, null=True, description="菜单状态（0正常 1停用）")

    perms = fields.CharField(max_length=100, null=True, description="权限标识")

    icon = fields.CharField(max_length=100, null=True, description="菜单图标")

    create_by = fields.CharField(max_length=64, null=True, description="创建者")

    create_time = fields.DatetimeField(null=True, description="创建时间")

    update_by = fields.CharField(max_length=64, null=True, description="更新者")

    update_time = fields.DatetimeField(null=True, description="更新时间")

    remark = fields.CharField(max_length=500, null=True, description="备注")

    class Meta:
        table = "sys_menu"

    def __str__(self):
        return f"{self.menu_id}"